/***************************************************
 @Name :        1196kk0
 @Time :        2025-05-26
 @Email :       2232506563@qq.com
 @Comment :     光电开关初始化
 @FileName :    drv_ITR.c
 @Version :     4.0
****************************************************/

#include "drv_ITR.h"

/***************************************
函数名：drv_ITR_Config
函数功能：对ITR引脚进行初始化 初始化外部中断
输入参数：无
输出参数：无
其它：//ITR     PB2     有遮挡为高电平
****************************************/
void drv_ITR_Config(void)
{
    GPIO_InitTypeDef GPIO_InitStruct;
    EXTI_InitTypeDef EXTI_InitStruct;
    NVIC_InitTypeDef NVIC_InitStruct;

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB , ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG , ENABLE);

    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;
    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
    GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_DOWN;
    GPIO_InitStruct.GPIO_Pin = GPIO_Pin_2;
    GPIO_Init(GPIOB , &GPIO_InitStruct);

    SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB , EXTI_PinSource2);

    EXTI_InitStruct.EXTI_LineCmd = ENABLE;                  // 自动中断
    EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;        // 模式选择 中断模式
    EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising;     // 边沿选择 上升沿
    EXTI_InitStruct.EXTI_Line = EXTI_Line2;            
    EXTI_Init(&EXTI_InitStruct);

    NVIC_InitStruct.NVIC_IRQChannel = EXTI2_IRQn;   
    NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 2;      // 抢占优先级
    NVIC_InitStruct.NVIC_IRQChannelSubPriority = 2;             // 响应优先级
    NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
 
    NVIC_Init(&NVIC_InitStruct);
}






